package cn.stylefeng.guns.modular.zdb.controller;

import cn.stylefeng.guns.modular.zdb.pojo.request.ZdbRequest;
import cn.stylefeng.guns.modular.zdb.service.ZdbService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 站点表控制器
 *
 * @author zhu
 * @date 2021/10/06 11:28
 */
@RestController
@ApiResource(name = "站点表")
public class ZdbController {

    @Resource
    private ZdbService zdbService;

    /**
     * 添加
     *
     * @author zhu
     * @date 2021/10/06 11:28
     */
    @PostResource(name = "添加", path = "/zdb/add")
    public ResponseData add(@RequestBody @Validated(ZdbRequest.add.class) ZdbRequest zdbRequest) {
        zdbService.add(zdbRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhu
     * @date 2021/10/06 11:28
     */
    @PostResource(name = "删除", path = "/zdb/delete")
    public ResponseData delete(@RequestBody @Validated(ZdbRequest.delete.class) ZdbRequest zdbRequest) {
        zdbService.del(zdbRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhu
     * @date 2021/10/06 11:28
     */
    @PostResource(name = "编辑", path = "/zdb/edit")
    public ResponseData edit(@RequestBody @Validated(ZdbRequest.edit.class) ZdbRequest zdbRequest) {
        zdbService.edit(zdbRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhu
     * @date 2021/10/06 11:28
     */
    @GetResource(name = "查看详情", path = "/zdb/detail")
    public ResponseData detail(@Validated(ZdbRequest.detail.class) ZdbRequest zdbRequest) {
        return new SuccessResponseData(zdbService.detail(zdbRequest));
    }

    /**
     * 获取列表
     *
     * @author zhu
     * @date 2021/10/06 11:28
     */
    @GetResource(name = "获取列表", path = "/zdb/list")
    public ResponseData list(ZdbRequest zdbRequest) {
        return new SuccessResponseData(zdbService.findList(zdbRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhu
     * @date 2021/10/06 11:28
     */
    @GetResource(name = "分页查询", path = "/zdb/page")
    public ResponseData page(ZdbRequest zdbRequest) {
        return new SuccessResponseData(zdbService.findPage(zdbRequest));
    }

}